package cn.woblog.android.common.utils.activity;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;

import cn.woblog.android.common.utils.IntentUtils;
import cn.woblog.android.common.utils.SPUtils;

/**
 * Public activity parent class,all the classes should be inherited.
 * Created by ren on 2015/4/27 0027.
 */
public class BaseActivity extends FragmentActivity {
    protected SPUtils spUtils;

    /**
     * @Bind(R.id.button1) Button button1;
     * http://jakewharton.github.io/butterknife/
     * 找控件
     */
    protected void initViews() {
    }

    /**
     * 动态设置样式，颜色，宽高，背景
     */
    protected void initStyles() {
    }

    /**
     * 设置数据
     */
    protected void initDatas() {

    }

    /**
     * 绑定监听器
     */
    protected void initListener() {
    }

    private void init() {
        beforeInit();
        initViews();
        initStyles();
        initDatas();
        initListener();
    }

    private void beforeInit() {
        spUtils = SPUtils.getInstance(getActivity().getApplicationContext());
    }

    //view 设置方法
    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        init();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        init();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        init();
    }

    //\view 设置方法

    protected FragmentActivity getActivity() {
        return this;
    }


    //activity 条转方法
    public void toActivity(Class<?> clazz) {
        IntentUtils.toActivity(getActivity(), clazz);
    }

    public void toActivityAfterFinishThis(Class<?> clazz) {
        IntentUtils.toActivityAfterFinishThis(getActivity(), clazz);
    }

    public void toActivityForResult(Intent intent, int requestCode) {
//        IntentUtils.toActivityForResut(getActivity(), intent, requestCode);
        startActivityForResult(intent, requestCode);
    }

    public void toActivityAfterFinishThis(Intent intent) {
        IntentUtils.toActivityAfterFinishThis(getActivity(), intent);
    }

    public void toActivity(Intent intent) {
        IntentUtils.toActivity(getActivity(), intent);
    }

    //\activity 条转方法

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.menu_main, menu);
//        return true;
//    }
//
//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        // Handle action bar item clicks here. The action bar will
//        // automatically handle clicks on the Home/Up button, so long
//        // as you specify a parent activity in AndroidManifest.xml.
//        int id = item.getItemId();
//
//        //noinspection SimplifiableIfStatement
//        if (id == R.id.action_settings) {
//            return true;
//        }
//
//        return super.onOptionsItemSelected(item);
//    }
}
